//
//  MyBillsViewController.m
//  HTP
//
//  Created by 王鑫 on 15/11/1.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "MyBillsViewController.h"
#import "MyBillsTableViewCell.h"

@interface MyBillsViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic,retain) UITableView *myBillsTableView;

@property (nonatomic,retain) NSDictionary *billDictionary;

@end

@implementation MyBillsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setDate];
    [self.view addSubview:self.myBillsTableView];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated {
    
}

- (UITableView *)myBillsTableView {
    if (!_myBillsTableView) {
        _myBillsTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeihgt - 64) style:UITableViewStyleGrouped];
        _myBillsTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_zhangdan"]];
        _myBillsTableView.dataSource = self;
        _myBillsTableView.delegate = self;
        _myBillsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    
    return _myBillsTableView;
}

//TODO:数据设置
- (void)setDate {
    _billDictionary = @{
                              @"icoUrl":@"shouru",
                              @"info":@"账号充值",
                              @"time":@"2015-11-02",
                              @"money":@"+100.00",
                              };
}

//TODO:tableView代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return  1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *idendef = @"Identifier";
    MyBillsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:idendef];
    
    if (cell == nil) {
        cell = [[MyBillsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idendef];
    }
    
    [cell setCellData:_billDictionary];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *sectionHeadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 30)];
    
    UILabel *sectionInfoLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 130, 20)];
    sectionInfoLabel.font = [UIFont systemFontOfSize:13.0f];
    sectionInfoLabel.textColor = [UIColor colorWithRed:0.388 green:0.388 blue:0.388 alpha:0.8];
    sectionInfoLabel.text = @"最近30天收支明细";
    [sectionHeadView addSubview:sectionInfoLabel];
    
    return sectionHeadView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
